package com.huawei.hgip.paintgame.activity;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import com.huawei.hgip.paintgame.R;
import com.huawei.hgip.paintgame.adapter.AppManageAdapter;
import com.huawei.hgip.paintgame.adapter.AppManageAdapter.OnAppManageNameClickListener;
import com.huawei.hgip.paintgame.app.ZZYYActivity;
import com.huawei.hgip.paintgame.m.data.Menu;

public class AppManageActivity extends ZZYYActivity {

	private ListView list;

	private AppManageAdapter mAppManageAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.appmanage);
		mAppManageAdapter = new AppManageAdapter(database.getAllMenuList(),
				database, new OnAppManageNameClickListener() {

					@Override
					public void onAppManageNameClick(Menu menu) {
						if (menu != null) {
							int newClickTimes = menu.getClickTimes() + 1;
							database.updateAppClickTimes(menu.getId(), newClickTimes);
							if (!menu.isNeedUpdate()) {
								Intent i = new Intent(menu.getAction());
								try {
									startActivity(i);
								} catch (ActivityNotFoundException e) {
								}
							}
						}
					}
				});
		list = (ListView) findViewById(R.id.appmanage_list);
		list.setAdapter(mAppManageAdapter);
	}

}
